package com.ad.pet.app;


import java.util.LinkedList;
import java.util.List;

import javax.inject.Inject;

import rx.Subscription;


/**
 * Created by z on.
 * Des:
 * Date: 2017/7/20
 */

public class RxDisposable {

    private List<Subscription> mSubscriptions;

    @Inject
    public RxDisposable() {
        mSubscriptions = new LinkedList<>();
    }

    public RxDisposable add(Subscription... subscription) {
        for (Subscription s : subscription) {
            if (s != null && !s.isUnsubscribed()) {
                mSubscriptions.add(s);
            }
        }
        return this;
    }

    public RxDisposable remove(Subscription... subscriptions) {
        for (Subscription subscription : subscriptions) {
            if (subscription != null) {
                subscription.unsubscribe();
                mSubscriptions.remove(subscription);
            }
        }

        return this;
    }

    public RxDisposable clear() {
        for (Subscription subscription : mSubscriptions) {
            if (subscription != null) {
                subscription.unsubscribe();
            }
        }
        mSubscriptions.clear();
        return this;
    }


}
